section .data

%macro C 0
	enter 0,0
	push esi
	push edi
	push ebx
%endmacro

%macro endC 0
	pop ebx
	pop edi
	pop esi
	leave
	ret
%endmacro

section .text
extern malloc
global suma
global negar
global esMayor
global producto
global power

suma:
	C
	mov eax,[ebp+8]  ;al
	mov edx,[ebp+12] ;ah
	add eax,[ebp+16] ;bl
	adc edx,[ebp+20] ;bh
	endC

negar:
	C
	mov eax,[ebp+8]
	mov edx,[ebp+12]
	not eax
	not edx
	inc eax
	adc edx,0
	endC

esMayor:
	C
	mov eax,[ebp+12] ;ah
	mov edx,[ebp+20] ;bh
	cmp eax,edx
	jg .si
	je .nose
	.no: mov eax,0
	jmp .listo
	.nose:
	mov eax,[ebp+8] ;al
	mov edx,[ebp+16] ;bl
	cmp eax, edx
	jle .no
	.si: mov eax,1
	.listo:
	endC

producto:
	C
	push dword 8
	call malloc
	pop ecx
	mov esi,eax
	mov eax,[ebp+8]
	mul dword [ebp+16]
	mov [esi],eax
	mov [esi+4],edx
	mov eax,esi
	endC

power:
	C
	mov eax,[ebp+8]
	xor edx,edx
	mov ecx,[ebp+12]
	call pow
	endC

pow:
	cmp ecx,1			;y==1?
	je .listo
	push 1
	shr ecx,1			;y/=2
	jnc .rec
	pop ebx
	push eax
	.rec:
	call pow
	mul eax				;edx:eax=x*x
	pop ebx
	mul ebx
	.listo:
	ret
